import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { _HttpClient, ModalHelper, SettingsService, TitleService} from '@delon/theme';
import {SimpleTableButton, SimpleTableColumn, SimpleTableComponent} from '@delon/abc';
import { NzMessageService, NzModalService, NzTabChangeEvent, UploadFile, NzNotificationService } from 'ng-zorro-antd';
import { CommService } from 'app/service/comm/comm.service';
import { Constant, ServiceResult } from '@core/constant';
import { EmitterService } from 'app/service/emit.service';
import { Router } from '@angular/router';
import { workplaceService } from '../../../service/workplace/workplace.service';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { Timeout } from '@shared/descriptor/timeout';

@Component({
  selector: 'workplace-list',
  templateUrl: './workplace-list.component.html',
  styleUrls: ['./workplace-list.component.less']
})
export class workplaceListComponent implements OnInit, OnDestroy {
  selectedIndex = 0;
  onSw = 0;
  // full = true;
  // region 公共字段
  workplace:any={
    fxjOut11: 35, //历史待放款
    fxjOut12: 21, //历史待核销
    fxjOut13: 28, //历史代偿订单
    fxjOut14: 15, //历史结清订单
    fxjOut15: 1688799, //历史放款金额

    fxjOut16: 5, //历史已放款订单
    fxjOut17: 680000, //
    fxjOut18: 3, //今日待放款订单
    fxjOut19: 410000, //
    fxjOut20: 20, //今日待核销订单
    fxjOut21: 245000, //
    fxjOut22: 18, //今日代偿申请订单
    fxjOut23: 80000, //
    fxjOut24: 3, //今日待结清订单
    fxjOut25: 120000, //
    fxjOut26: 52, //本月放款订单量
    fxjOut27: 1680000, //
  };
  selectHero(id):void{
    this.onSw = id;
    switch (this.onSw) {
      case 0:
          this.q.orderStatus = "";
          this.columns = this.columns;
        break;
      case 1:
        this.q.orderStatus = "历史待放款";
        this.columns = this.columns1;
        break;
      case 2:
        this.q.orderStatus = '历史待核销';
        this.columns = this.columns;
        break;
      case 3:
        this.q.orderStatus = '历史代偿订单';
        this.columns = this.columns;
        break;
      case 4:
        this.q.orderStatus = '历史结清订单';
        this.columns = this.columns;
        break;
      case 5:
        this.q.orderStatus = '历史放款金额';
        this.columns = this.columns;
        break;
      case 6:
        this.q.orderStatus = '历史已放款订单';
        this.columns = this.columns;
        break;
      case 7:
        this.q.orderStatus = '今日待放款订单';
        this.columns = this.columns;
        break;
      case 8:
        this.q.orderStatus = '今日待核销订单';
        this.columns = this.columns;
        break;
      case 9:
        this.q.orderStatus = '今日代偿申请订单';
        this.columns = this.columns;
        break;
      case 10:
        this.q.orderStatus = '今日待结清订单';
        this.columns = this.columns;
        break;
      case 11:
        this.q.orderStatus = '本月放款订单量';
        this.columns = this.columns;
        break;
      default:
        break;
    }
    this.st.load(1, this.q);
  }
  visible = false;
  // pageSize
  ps = 10;
  // 搜索表单
  q: any = {
    bpmStatus:"",
  };

  loading = false;
  // 表格组件
  @ViewChild('st') st: SimpleTableComponent;
  // 表格数据url
  url = this.workplaceService.list();
  // region end

  // 搜索区域显示/隐藏标记
  // 显示图片
  previewVisible = false;
  // 大图地址
  previewImage = '';
  imgSuffix = '';

  years = [];
  userGroups = [];
  brands = [];
  seasons = [];
  checkedList = [];
  data = [];

  // uploadUrl = this.workplaceService.uploadProds();
  uploadDateUrl = this.workplaceService.batchRepdate();



  // 页面初始化加载
  columns: SimpleTableColumn[] = [
    {
      title: '操作',
      buttons: [
        {
          text: '审批',
          type: 'link',
          // click: (record: any) => this.router.navigate([record.wbUrl+record.id]),
          click: (record: any) => this.router.navigate(['/workplace/workplace/rm/'+record.id]),
          iif: (item: any, btn: SimpleTableButton, column: SimpleTableColumn) => {
            // return item.bpmStatus === '1'
            return item.wbName === 'OK'
          }
        },
        {
          text: '查看',
          type: 'link',
          click: (record: any) => this.router.navigate(['/workplace/workplace/edit/'+record.id])
        }
        // ,{
        //   text: '还款计划',
        //   type: 'link',
        //   click: (record: any) => this.router.navigate(['/pl/replan/'+record.orderNo])
        // },
        // {
        //   text: '逾期清单',
        //   type: 'link',
        //   click: (record: any) => this.router.navigate(['/plo/plo/'+record.orderNo])
        // },
        // {
        //   text: '逾期处理',
        //   type: 'link',
        //   click: (record: any) => this.router.navigate(['/plop/plop/'+record.orderNo])
        // },
        // {
        //   text: '逾期提醒',
        //   type: 'link',
        //   click: (record: any) => this.router.navigate(['//notice/notice/'+record.orderNo])
        // }
      ]
    },
    // { title: '', index: 'key', type: 'checkbox' },
    { title: '订单编号', index: 'orderNo' },
    { title: '订单状态', index: 'orderStatus' },
    { title: '产品', index: 'proName' },
    { title: '客户姓名 ', index: 'cusName'},
    { title: '身份证号 ', index: 'cusIncard' },
    { title: '联系电话', index: 'cusMobile' },
    { title: '申请金额 ', index: 'orderAmount' },
    { title: 'GPS安装时间 ', index: 'gpsInsData' },
    { title: '车辆信息 ', index: 'cusRemark' },
    { title: '录入业务员  ' , index: 'createBy' },
    { title: '订单提交时间', index: 'createDate' },
    { title: '审批人员', index: 'updateBy' }


  ];
  columns1: SimpleTableColumn[] = [
    { title: '', index: 'key', type: 'checkbox' },
    { title: '订单编号', index: 'orderNo' },
    { title: '客户姓名 ', index: 'cusName'},
    { title: '订单状态', index: 'orderStatus' },
    { title: '产品', index: 'proName' },
    { title: '身份证号 ', index: 'cusIncard' },
    { title: '联系电话', index: 'cusMobile' },
    { title: '申请金额 ', index: 'orderAmount' },
    { title: 'GPS安装时间 ', index: 'gpsInsData' },
    { title: '车辆信息 ', index: 'cusRemark' },
    { title: '录入业务员  ' , index: 'createBy' },
    { title: '订单提交时间', index: 'createDate' },
    { title: '审批人员', index: 'updateBy' },
    {
      title: '操作',
      buttons: [
        {
          text: '审批',
          type: 'link',
          // click: (record: any) => this.router.navigate([record.wbUrl+record.id]),
          click: (record: any) => this.router.navigate(['/workplace/workplace/rm/'+record.id]),
          iif: (item: any, btn: SimpleTableButton, column: SimpleTableColumn) => {
            // return item.bpmStatus === '1'
            return item.wbName === 'OK'
          }
        },
        {
          text: '查看',
          type: 'link',
          click: (record: any) => this.router.navigate(['/workplace/workplace/edit/'+record.id])
        }
      ]
    },


  ];

  
  constructor(
    public setting: SettingsService,
    private trans: TranslateService,
    public http: _HttpClient,
    public msg: NzMessageService,
    private modalSrv: ModalHelper,
    private comm: CommService,
    private cnt: Constant,
    private workplaceService: workplaceService,
    private emit: EmitterService,
    private router: Router,
    private modalService: NzModalService,
    private notice: NzNotificationService,
  ) {}
  syncing = false;
  lastDate = null;

  ngOnDestroy() {
    if (this.inter) {
      clearInterval(this.inter);
    }
  }

  inter
  ngOnInit() {
    this.imgSuffix = this.comm.getGoodsUrl();

    this.emit.getMessage().subscribe(data => {
      if (data.text === 'RELOAD_GOODS_LIST') {
        this.st.load(1, this.q);
      }
    });

    this.getBiList();


  }

  fullChange(val: boolean) {
    // this.scroll = val ? { y: '350px' } : { y: '230px' };
  }

  getBiList() {
    // console.log(this.workplaceService.getZx())
    this.workplaceService.bilist().pipe(
      catchError(err => {
        return of(err);
      })
    ).subscribe(data => {
      console.log(data);
      if(data.data !=null&&data.data.length>0){
        let i = Number(data.data.length) - Number(1);
        this.workplace = data.data[i];
        console.log(this.workplace);
      }
      
      // this.titleService.setTitle("征信报告("+this.product.orderNo+")");
    });
  }





  checkboxChange(list: any[]) {
    this.checkedList = list;
  }


  close(): void {
    this.visible = false;
  }



  cancel() {
    this.repdate = null;
  }
  repdate = null;

  change(args) {
    this.selectedIndex = args.index;
  }

}
